package cn.java76.springboot.demo1.service;


import cn.java76.springboot.demo1.dao.OAdminMapper;
import cn.java76.springboot.demo1.entity.OAdmin;
import cn.java76.springboot.demo1.vo.AjaxPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Cacheable(cacheNames = "admin",keyGenerator = "keyunkey")
public class OAdminService {

    @Autowired
    private OAdminMapper mapper;

    public OAdmin findname(String username) {

        return mapper.findname(username);

    }

    public AjaxPage search(int page, int limit, String name, String tele) {
        List<OAdmin> search = this.mapper.search(page, limit, name, tele);
        int i = this.mapper.searchTotal(name, tele);
        return new AjaxPage(search, i, limit, page);
    }

    //清除所有的缓存,CUD
    @CacheEvict(allEntries = true,cacheNames = "admin")
    public int add(OAdmin oAdmin) {
        return mapper.add(oAdmin);
    }

    public int update(OAdmin oAdmin) {

        return mapper.update(oAdmin);

    }

    public int del(long id) {

        return mapper.del(id);

    }

    public OAdmin get(long id) {

        return mapper.get(id);

    }

//    public OAdmin modify(String username,String password) {
//
//            return mapper.modify(username,password);
//
//    }

    public OAdmin login(String uname, String upass) {
        OAdmin f = this.mapper.findname(uname);
        if (f != null && f.getUpass().equals(upass))
            return f;
        return null;
    }
}